# R script for  running all code files automatically
# This file calls and runs all four R scripts needed for replicating all results in the paper 

# Note: 
## Optional usage: one need not use this file in practice if separate runs with targeted focus is preferred
## Directory management: make sure all replication files are stored in the same (sub)directory to avoid path issues

rm(list = ls())

script_names <- paste0(
  "R_", # common prefix for code files
  c(
    '00_prepare_data', # this one prepares data
    '01_compute_ranks', # this one runs main analysis
    '02_compute_extra', # this one runs supplemental analysis
    '03_include_status' # this one runs further analysis
  ),
  '.R' # common suffix for code files
)

all(sapply(script_names, file.exists))==TRUE # all scripts correctly named and accessible

if (!dir.exists('Tables/')) dir.create('Tables/') # create a container for table outputs
if (!dir.exists('Figures/')) dir.create('Figures/') # create a container for graphic outputs
  
for (script in script_names) {
  # run each script in set order
  source(script)
  rm(list = ls())
  gc()
}

# END #
